package com.zuoye.day14;

import java.io.*;

public class CopyFile {
    public static void main(String[] args) {
        File oldFile = new File("d://test1/hello.txt");

        File newFile = new File("d://test2/hello.txt");
        File fileParent = newFile.getParentFile();

        if (!fileParent.exists()){
            fileParent.mkdirs();
        }
        if (!newFile.exists()){
            try {
                newFile.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        FileOutputStream os = null;
        try {
            os = new FileOutputStream(newFile);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        FileInputStream in = null;
        try {
             in = new FileInputStream(oldFile);
             int data;
             while ((data = in.read()) != -1){
                os.write(data);
             }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                in.close();
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }








    }
}
